package com.flexandair.model
{
	import com.flexandair.view.components.ObjectDesignerCanvas;
	
	import mx.collections.ArrayCollection;
	
	import org.puremvc.as3.interfaces.IProxy;
	import org.puremvc.as3.patterns.proxy.Proxy;

	public class ClassesProxy extends Proxy implements IProxy
	{
		public static const NAME:String = "classesProxy";
		public static const GET_CLASSES_SUCCESS:String = "GET_CLASSES_SUCCESS";
		public static const CLASS_ADDED:String = "CLASS_ADDED";
		public static const NO_CLASSES_FOUND:String = "NO_CLASSES_FOUND";
		
		private var _classes:ArrayCollection;
		
		public function ClassesProxy(proxyName:String=null, data:Object=null)
		{
			super(proxyName, data);
		}
		
		override public function getProxyName():String
		{
			return NAME;
		}
		
		public function addClass( value:ObjectDesignerCanvas ) :void
		{
			_classes.addItem( value );
			sendNotification(CLASS_ADDED, value);
		}
		
		public function removeClass( value:ObjectDesignerCanvas ) :void
		{
			if ( _classes.getItemIndex( value ) != -1 )
			{
				_classes.removeItemAt(_classes.getItemIndex( value ) );
			}
		}
		
		public function getClasses() : void
		{
			if ( _classes.length > 0 )
			{
				sendNotification( GET_CLASSES_SUCCESS, _classes);
			}
			else
			{
				sendNotification( NO_CLASSES_FOUND );
			}
		}
		
		override public function onRegister():void
		{
			_classes = new ArrayCollection();
		}
		
		override public function onRemove():void
		{
			_classes = new ArrayCollection();
		}
		
	}
}